<template>
  <div>

<el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/admin/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 搜索部分 -->
    <el-form :inline="true">
      <el-form-item>
        <el-input placeholder="请输入要搜索得商品"  style="width:350px;">
          <el-button icon="el-icon-search" slot="append"></el-button>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="$router.push('/admin/goods/create')">添加商品</el-button>
      </el-form-item>
    </el-form>


    <!-- table列表区域 -->
    <el-table border :data="goods_list">
      <el-table-column label="ID" width="60px" prop="goods_id"></el-table-column>
      <el-table-column label="商品名称" width="300px" prop="goods_name"></el-table-column>
      <el-table-column label="商品价格(元)" prop="goods_price"></el-table-column>
      <el-table-column label="商品重量" prop="goods_weight"></el-table-column>
      <el-table-column label="创建时间" prop="add_time">
        <template slot-scope="scope">
          <div>
            {{scope.row.add_time | formatDate}}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template>
          <div>
            <el-button size="mini" type="primary" icon="el-icon-edit"/>
             <el-button size="mini" type="danger" icon="el-icon-delete"/>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页器 -->
    <div style="margin-top:20px">
      <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    :current-page="pagenum"
    :page-size="pagesize"
    :page-sizes="[3,6,9,12]"
    layout="total,sizes,prev,pager,next,jumper"
    :total="total"
    />
    </div>
    
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      goods_list:[],
      query:'',
      pagenum:1,
      pagesize:3,
      total:0,
    };
  },
  mounted() {
    this.getGoodsList();//调用
   
  },
  methods: {
  
    //分页
    handleSizeChange(pagesize){
      console.log(pagesize)
      this.pagesize=pagesize
      this.getGoodsList()
    },
    handleCurrentChange(pagenum){
      console.log(pagenum)
      this.pagenum=pagenum
      this.getGoodsList()
    },
    // 获取商品列表
     getGoodsList(){
      //请求添加用户的接口
      let url = this.$store.state.baseUrl; //请求接口的基地址

      this.$axios.get(`${url}goods?query=${this.query}&pagenum=${this.pagenum}&pagesize=${this.pagesize}`).then(res=>{
        console.log(res);
        this.goods_list = res.data.goods;//商品列表数据
        this.total = res.data.total;//商品总条数
      })
    },
  },
  computed: {},
  watch: {}
};
</script>

<style>
.el-breadcrumb{
  margin-bottom: 30px;
}
</style>